package com.ruoyi._.controller.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.Storagelocations;
import com.ruoyi.service.IStoragelocationsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货架/存储位置表Controller
 * 
 * @author ruoyi
 * @date 2025-06-16
 */
@Controller
@RequestMapping("/pims/storagelocations")
public class StoragelocationsController extends BaseController
{
    private String prefix = "pims/storagelocations";

    @Autowired
    private IStoragelocationsService storagelocationsService;

    @RequiresPermissions("pims:storagelocations:view")
    @GetMapping()
    public String storagelocations()
    {
        return prefix + "/storagelocations";
    }

    /**
     * 查询货架/存储位置表列表
     */
    @RequiresPermissions("pims:storagelocations:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Storagelocations storagelocations)
    {
        startPage();
        List<Storagelocations> list = storagelocationsService.selectStoragelocationsList(storagelocations);
        return getDataTable(list);
    }

    /**
     * 导出货架/存储位置表列表
     */
    @RequiresPermissions("pims:storagelocations:export")
    @Log(title = "货架/存储位置表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Storagelocations storagelocations)
    {
        List<Storagelocations> list = storagelocationsService.selectStoragelocationsList(storagelocations);
        ExcelUtil<Storagelocations> util = new ExcelUtil<Storagelocations>(Storagelocations.class);
        return util.exportExcel(list, "货架/存储位置表数据");
    }

    /**
     * 新增货架/存储位置表
     */
    @RequiresPermissions("pims:storagelocations:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存货架/存储位置表
     */
    @RequiresPermissions("pims:storagelocations:add")
    @Log(title = "货架/存储位置表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Storagelocations storagelocations)
    {
        return toAjax(storagelocationsService.insertStoragelocations(storagelocations));
    }

    /**
     * 修改货架/存储位置表
     */
    @RequiresPermissions("pims:storagelocations:edit")
    @GetMapping("/edit/{locationId}")
    public String edit(@PathVariable("locationId") Long locationId, ModelMap mmap)
    {
        Storagelocations storagelocations = storagelocationsService.selectStoragelocationsByLocationId(locationId);
        mmap.put("storagelocations", storagelocations);
        return prefix + "/edit";
    }

    /**
     * 修改保存货架/存储位置表
     */
    @RequiresPermissions("pims:storagelocations:edit")
    @Log(title = "货架/存储位置表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Storagelocations storagelocations)
    {
        return toAjax(storagelocationsService.updateStoragelocations(storagelocations));
    }

    /**
     * 删除货架/存储位置表
     */
    @RequiresPermissions("pims:storagelocations:remove")
    @Log(title = "货架/存储位置表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(storagelocationsService.deleteStoragelocationsByLocationIds(ids));
    }
}
